package com.yequan.ymdemo.presenter;

import com.yequan.ymdemo.model.MvpModel;
import com.yequan.ymdemo.view.MvpView;

import java.lang.ref.WeakReference;

/**
 * Created by Administrator on 2016/10/19.
 */

public abstract class MvpPresenter<M extends MvpModel,V extends MvpView> {
    private M model;
    private WeakReference<V> weakReference;
    public void attach(V v){
        weakReference=new WeakReference<V>(v);
    }
    public void dettach(){
        if (weakReference!=null){
            weakReference.clear();
            weakReference=null;
        }
    }
    public V getView(){
        if (weakReference!=null){
            return weakReference.get();
        }
        return null;
    }
    public MvpPresenter(){
        model=createModel();
    }
    public abstract M createModel();
}
